//
//  CustumTabBarController.m
//  暴走段子_王桂敏
//
//  Created by 王桂敏 on 15/6/1.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "CustumTabBarController.h"
#import "DuanziViewController.h"
@interface CustumTabBarController ()
- (void)_setup;//设置tabbarcontroller
- (UINavigationController *)_navigationControllerWithClass:(Class)class;//根据制定的视图控制器类型创建对象以及 导航控制器
@end

@implementation CustumTabBarController


- (UINavigationController *)_navigationControllerWithClass:(Class)class{
    UIViewController *aViewController = [[class alloc] init];
    UINavigationController *navigaion = [[UINavigationController alloc] initWithRootViewController:aViewController];
    [aViewController release];
    return navigaion;
}

- (void)_setup{
    NSArray *imageNames = @[@"icon_main",@"main_tab_discovery",@"icon_me"];
    NSArray *titles = @[@"段子",@"发现",@"我"];
    NSArray *classNames = @[@"DuanziViewController",@"FindViewController",@"MyselfViewController"];
    NSMutableArray *viewControllers = [NSMutableArray array];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor orangeColor]}];
    for (int i = 0; i < titles.count; i++) {
        UINavigationController *aNavi = [self _navigationControllerWithClass:NSClassFromString(classNames[i])];

        aNavi.tabBarItem = [[[UITabBarItem alloc] initWithTitle:titles[i] image:[[UIImage imageNamed:imageNames[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:[imageNames[i] stringByAppendingString:@"_active"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]] autorelease];
        [viewControllers addObject:aNavi];
        [aNavi release];
    }
    self.viewControllers = viewControllers;
    self.tabBar.tintColor = [UIColor orangeColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _setup];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
